//
// Created by 32827 on 2024/2/1.
//

#ifndef YZGD32_YZL_UI__WIDGET_PP_BASE_HPP
#define YZGD32_YZL_UI__WIDGET_PP_BASE_HPP

#include "yzl_ui_include.h"

typedef struct {
    void *p_this;//指向WidgetBase C++ 对象
} WidgetBaseData;//链接C 与 C++ 位于YZL_WIDGET.Data
//TODO: 所有权 转移 C++ -> C 写YZL_WIDGET.Data区，并转移draw touch dispose权限
class WidgetBase{
    //C:View dispose ->del ~WidgetBase() -> disposeP()
    //C++:View del ~WidgetBase() -> disposeP()
public:
    YZL_WIDGET *instance;           //C 层实例
    YZF_BOOL isBackup=YZF_FALSE;    //是否已经备份
    Yz_Color *recover;              //备份的被覆盖的显存内容
    WidgetBase(YZL_WIDGET *Ram,int x, int y,int z, int width, int height);
    ~WidgetBase();

    virtual void drawP();

    virtual YZF_BOOL touchP(uint16_t x,uint16_t y,YZL_UI_CTR_EVENT event);

    virtual void disposeP();

    void BackUp();
    void Restore();
    //兼容C层的调用
    static void draw(void *widget);                                             //由具体控件实现
    static YZF_BOOL touch(uint16_t x,uint16_t y,YZL_UI_CTR_EVENT event,void *widget);   //由具体控件实现
    static void dispose(void *widget);
};
#endif //YZGD32_YZL_UI__WIDGET_PP_BASE_HPP
